<?php

namespace App\Dao;

use App\Model\Topic;
use App\Model\TopicReply;
use App\Model\TopicTag;
use App\Model\TopicZan;
use App\Utils\AliyunOssHelper;
use App\Utils\FunUtil;
use App\Utils\MemcacheClient;
use Hyperf\Context\ApplicationContext;

class TopicReplyDao
{
    private static $instance;

    public static function getInstance()
    {
        if (!self::$instance) {
            self::$instance = Applicationcontext::getcontainer()->get(self::class);
        }
        return self::$instance;
    }

    /**
     * 获取帖子回帖数据
     * @param $t_id
     * @param $page
     * @param $pagesize
     * @return mixed
     */
    public function getAllReply($t_id, $page, $pagesize)
    {
        $start = ($page - 1) * $pagesize;
        return TopicReply::query()->from('tb_topic_reply AS r')
            ->select(['r.*', 'u.sex', 'u.nickname', 'u.head_image'])
            ->leftJoin('tb_user AS u', 'r.uid', '=', 'u.id')
            ->where('r.t_id', '=', $t_id)
            ->where('r.status', '=', 0)
            ->skip($start)
            ->limit($pagesize)
            ->get()
            ->toArray();
    }

}